package MultiThread;

public class BuyTickets implements Runnable {

    private volatile int num = 10;

    @Override
    public void run() {
        while (num > 0) {
            System.out.println(Thread.currentThread().getName() +  ":拿到了第"+ num-- +"张票");
//            try {
//                Thread.sleep(100);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        BuyTickets a = new BuyTickets();

        new Thread(a,"A线程").start();
        new Thread(a,"B线程").start();
        new Thread(a,"C线程").start();

        Thread.sleep(2000);
        System.out.println("休息2s");
        a.num = 10;
        new Thread(a, "D线程").start();
    }
}
